home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
United Public Domain Gold 4
/
United Public Domain Gold 4.iso
/
fredfish
/
ff.0536.dms
/
ff.0536.adf
/
IncRev
/
src.lzh
/
increv.c
next >
Wrap
C/C++ Source or Header
|
1991-08-23
|
8KB
|
303 lines
/***************************************************************************
* increv.c : automatic update of version and revision numbers *
* *
* File rev.c must have the following format: *
* *
* char ProgId[]="..."; *
* char Version[]="..."; *
* int Revision = x; *
* char UserId[]="..."; *
* char Date[]="..."; *
* *
* where ... may be any character *
* and x *MUST* be a number *
* *
* each line *MUST NOT* contain more than 79 characters *
* *
***************************************************************************/
/* --------------------- source code revisions, kept by RCS ------------- */
/* $Header: Hard0:C-Compiler/src/increv/rcs/increv.c,v 1.0 91/08/12 14:41:12 Mtwx Exp $ */
/* $Log: increv.c,v $
* Revision 1.0 91/08/12 14:41:12 Mtwx
* Initial revision
*
* Revision 1.1 91/08/12 14:40:26 Mtwx
* Initial revision
* */
/* ------------------------------- includes ----------------------------- */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "increv.h"
char Mon[12][4]={ "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep",
"Oct","Nov","Dec" };
char IncrevV[80];
/* forward references */
void readerror(), usage();
/* ----------------------- external references ------------------ */
extern char ProgId[],Version[],Date[];
extern int Revision;
main(argc,argv)
int argc;
char *argv[];
{
FILE *datei,*datei2;
struct tm *newtime;
long ltime;
char dummy[80];
char ProgramId[80],VersionId[80], Revisionnr[80], UserId[80],
Datum[80];
char new_ProgId[80],new_Version[80],new_Revision[80],new_UserId[80],
new_Date[80]; /* contain updated strings */
char NewId[80]; /* contains user desired ProgId */
char NewVersion[80]; /* contains user desired Version no */
char *newuserid; /* contains user desired UserId */
char Filename[FILENAME_LENGTH+1]; /* contains (optional) filename */
int i,rev,new_rev;
unsigned int Params=NULL;
sprintf(IncrevV,"%s V%s/%d - %s (C) 1991 Metalworx",ProgId,Version,
Revision,Date);
printf("\n%s\n",IncrevV);
if(argc>1)
{
if(argv[1][0]=='?')
{
usage();
exit(0);
}
for(i=1;i<argc;i++)
{
switch(argv[i][1])
{
case 'c':
Params|=CREATE_FILE;
puts("Create new rev file");
if(strlen(argv[i])>2) /* optional filename ? */
strcpy(Filename,&argv[i][2]);
break;
case 'd':
Params|=DATE_UPD_ONLY;
puts("Date update only");
break;
case 'v':
Params|=NEW_VERSION;
strcpy(NewVersion,&argv[i][2]);
break;
case 'r':
Params|=NEW_REVISION;
sscanf(&argv[i][2],"%3d",&new_rev);
break;
case 'u':
Params|=NEW_USER;
newuserid=&argv[i][2];
break;
case 'i':
Params|=NEW_ID;
strcpy(NewId,&argv[i][2]);
break;
case '?':
usage();
exit(0);
default :
printf("Unknown option %s\n",argv[i]);
usage();
exit(1);
}
}
}
datei=fopen((char *)"rev.c","r");
if(datei)
{
fgets(ProgramId,79,datei);
/* check & print Programm-ID */
i=strpos(ProgramId,"=");
if (i!=-1)
printf("Programm-ID : %s",&ProgramId[i+1]);
else readerror();
fgets(VersionId,79,datei);
/* check & print Version-No. */
i=strpos(VersionId,"=");
if (i!=-1)
printf("Version-No : %s",&VersionId[i+1]);
else readerror();
fgets(Revisionnr,79,datei);
fgets(UserId,79,datei);
/* check & print UserID */
i=strpos(UserId,"=");
if (i!=-1)
printf("UserId : %s",&UserId[i+1]);
else readerror();
fgets(Datum,79,datei);
/* check & print Date */
i=strpos(Datum,"=");
if (i!=-1)
printf("last Update : %s",&Datum[i+1]);
else readerror();
fclose(datei);
puts("----------------------------------------------------------");
if((Params & NEW_ID) && (!(Params & DATE_UPD_ONLY)))
{
i=strpos(ProgramId,"=");
strncpy(new_ProgId,ProgramId,i+1);
new_ProgId[i+1]='\0';
sprintf(dummy,"\"%s\";\n",NewId);
strcat(new_ProgId,dummy);
printf("new program-id : %s",dummy);
}
else
strcpy(new_ProgId,ProgramId);
if((Params & NEW_VERSION) && (!(Params & DATE_UPD_ONLY)))
{
i=strpos(VersionId,"=");
strncpy(new_Version,VersionId,i+1);
new_Version[i+1]='\0';
sprintf(dummy,"\"%s\";\n",NewVersion);
strcat(new_Version,dummy);
printf("new Version-No : %s",dummy);
}
else
strcpy(new_Version,VersionId);
/* get & update revision number */
i=strpos(Revisionnr,"=");
rev=atoi(&Revisionnr[i+1]);
if(Params & DATE_UPD_ONLY) /* Don't update revision no. */
printf("keeping old revision-no. :%3d\n",rev);
else
{
if(Params & NEW_REVISION)
rev=new_rev;
else
{
if(Params & NEW_VERSION) /* set Revision no. back to 1 */
rev=0;
rev++;
}
printf("updating to new revision-no. :%3d\n",rev);
}
strncpy(new_Revision,Revisionnr,i+1);
new_Revision[i+1]='\0';
sprintf(dummy,"%3d;",rev);
strcat(new_Revision,dummy);
/* get & update system-date */
time(<ime);
i=strpos(Datum,"=");
strncpy(new_Date,Datum,i+1);
new_Date[i+1]='\0';
newtime=localtime(<ime);
sprintf(dummy,"\"%2d-%s-%2d\";\n",newtime->tm_mday,Mon[newtime->tm_mon],
newtime->tm_year);
strcat(new_Date,dummy);
printf("updating to new date : %s",dummy);
/* update UserId, if ENV-Variable exists! */
if(Params & DATE_UPD_ONLY)
{
puts("keeping old UserId!");
strcpy(new_UserId,UserId);
}
else
{
if(!(Params & NEW_USER)) /* get env-variable if not -u */
#ifdef UNIX
newuserid=getenv("USERNAME");
#endif
#ifdef AMIGA
newuserid=getenv("USERNAME");
#endif
#ifdef MSDOS
newuserid=getenv("USERNAME");
#endif
if(newuserid!=NULL)
{
if(Params & NEW_USER)
printf("updating UserId (set by -u ) : %s\n",newuserid);
else
#ifdef AMIGA
printf("updating UserId (set by SETENV): %s\n",newuserid);
#endif
#if MSDOS || UNIX
printf("updating UserId (set by SET) : %s\n",newuserid);
#endif
i=strpos(UserId,"=");
strncpy(dummy,UserId,i+1);
dummy[i+1]='\0';
sprintf(new_UserId,"%s\"%s\";\n",dummy,newuserid);
}
else strcpy(new_UserId,UserId);
}
/* write file */
datei2=fopen((char *)"rev.c","w");
if(datei2)
{
fprintf(datei2,"%s",new_ProgId);
fprintf(datei2,"%s",new_Version);
fprintf(datei2,"%s\n",new_Revision);
fprintf(datei2,"%s",new_UserId);
fprintf(datei2,"%s",new_Date);
fclose(datei2);
}
else puts("Error while opening write file!");
}
else
{
puts("File rev.c not found!");
readerror();
}
}
void readerror()
{
puts("\nError reading input-file (rev.c)!");
puts("Programm terminated by error!");
exit(1);
}
void usage()
{
#ifdef MSDOS
printf("%c[1;31mUsage: increv [[-]?] [-d] [-i<ID>] [-r<No.>] [-u<USER>] [-v<No.>]\n",
27);
printf("%c[36mOptions: -? displays this text\n",27);
#endif
#if AMIGA || UNIX
puts("Usage: increv [[-]?] [-d] [-i<ID>] [-r<No.>] [-u<USER>] [-v<No.>]");
puts("Options: -? displays this text");
#endif
/* puts(" -c[FILE] create new rev file. Filename will be FILE or");
puts(" rev.c on default."); for later use */
puts(" -d date update only (all other options are ignored)");
puts(" -i<ID> update ProgId with ID, can be any text");
puts(" -r<No.> update revision no. with No.");
puts(" No. must be an integer!");
puts(" -u<USER> update UserId with USER, can be any text");
puts(" -v<No.> update version with No.");
#ifdef MSDOS
printf(" No. can be any text\n%c[0m",27);
#endif
#if AMIGA || UNIX
puts(" No. can be any text");
#endif
}